#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>

using namespace std;
using ll = long long;

ll solve() {
	ll a, b;
	cin >> a >> b;
	if (a % 2 == 0) {
		if (b % 2 == 0) {
			return a * (b / 2) + 2;
		} else {
			return -1;
		}
	}
	else {
		if (b % 2 != 0) {
			return a * b + 1;
		} else {
			if (b % 4 == 0) {
				return a * (b / 2) + 2;
			} else {
				return -1;
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin >> t;
	while (t-- > 0) {
		cout << solve() << endl;
	}
	return 0;
}
